package com.example.dangdangbackend.controller;

import com.example.dangdangbackend.DTO.AddAddressDTO;
import com.example.dangdangbackend.VO.AddressDetailVO;
import com.example.dangdangbackend.entity.Address;
import com.example.dangdangbackend.entity.Result;
import com.example.dangdangbackend.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
@Slf4j
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/addAddress")
    public Result addAddress(AddAddressDTO addAddressDTO){

        addressService.addAddressService(addAddressDTO);

        return Result.success();
    }

    @PostMapping("/selectAddressDetail")
    public Result<List<AddressDetailVO>> selectAddressDetail(){
        return  Result.success(addressService.selectAddressDetail());
    }

    @PostMapping("/deleteAddress")
    public Result deleteAddressById(int addressId){
        addressService.deleteAddress(addressId);

        return Result.success();
    }

    @PostMapping("/updateAddress")
    public Result updateAddressById(Address address){
        addressService.updateAddress(address);
        return Result.success();
    }
}
